package com.browsesoft.htmlcomponent;

import javax.servlet.http.HttpServletRequest;

import org.w3c.dom.Element;
import org.w3c.dom.Text;

import com.browsesoft.ExtendElement;
import com.browsesoft.user.User;

public class HTMLUserComponent extends HTMLBasicComponent {
	public HTMLUserComponent(HTMLBasicComponent parent) throws Exception {
		super(parent);
	}

	public void init(HttpServletRequest request, Element e) throws Exception {
		super.init(request, e);
		loginUser = (User) request.getSession().getAttribute("loginUser");
	}

	/**
	 * 根据Model的内容更新需要处理的元素内容，在产生页面时要调用 这个哈西表是
	 * 
	 * @throws java.lang.Exception
	 */
	protected void updateElement() throws Exception {
		// 找到user页面元素
		Element userElement = (Element) ExtendElement.findElementsByTagName(
				this.getElement(), "user", "name", "user").get(0);
		// 页面表现用户名称
		Text text = ((HTMLPage) this.getPage()).getDocument().createTextNode(
				loginUser.getName());
		ExtendElement.replaceElementContext(userElement, text);
	}

	/**
	 * 用户
	 */
	private User loginUser = null;
}